package com.myecl.poker.communication;

import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

import com.myecl.poker.option.Command;
import com.myecl.poker.state.Player;

public class CommandHandler {
	public Map<Player, List<Command>> commands = new HashMap<Player, List<Command>>();
	
	public CommandHandler() {
	}
	
	public void addCommand(Player player, Command command) {
		if (commands.containsKey(player)) {
			commands.get(player).add(command);
		} else {
			List<Command> commandList = new LinkedList<Command>();
			commandList.add(command);
			commands.put(player, commandList);
		}
	}
	
	public List<Command> getCommands(Player player) {
		return commands.get(player);
	}
	
	
	public void clean(List<Player> players) {
		for(Player p: commands.keySet()) {
			if (!players.contains(p)) {
				commands.remove(p);
			}
		}
	}
}
